package com.hitsz.cdq;

import android.app.Fragment;
import android.app.FragmentManager;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;

/**
 * Created by ChenDongqiang on 2017/6/26.
 */
public class MonitorFragment extends Fragment {

    private Button btn_che_all,btn_che_online,btn_che_add;
    private TextView tv_all_line,tv_online_line,tv_add_line;
    private FragmentManager fm;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.content_monitor, container, false);

        btn_che_all= (Button) view.findViewById(R.id.btn_che_all);
        btn_che_online= (Button) view.findViewById(R.id.btn_che_online);
        btn_che_add= (Button) view.findViewById(R.id.btn_che_add);

        tv_all_line= (TextView) view.findViewById(R.id.tv_all_line);
        tv_online_line= (TextView) view.findViewById(R.id.tv_online_line);
        tv_add_line= (TextView) view.findViewById(R.id.tv_add_line);

        fm = getFragmentManager();
        Fragment fg = new CheAllFragment();
        fm.beginTransaction().replace(R.id.content_che_frame_layout, fg).commit();

        btn_che_all.setEnabled(false);
        btn_che_all.setTextColor(Color.WHITE);
        tv_all_line.setVisibility(View.VISIBLE);
        btn_che_online.setEnabled(true);
        btn_che_online.setTextColor(Color.LTGRAY);
        tv_online_line.setVisibility(View.INVISIBLE);
        btn_che_add.setEnabled(true);
        btn_che_add.setTextColor(Color.LTGRAY);
        tv_add_line.setVisibility(View.INVISIBLE);


        btn_che_all.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                btn_che_all.setEnabled(false);
                btn_che_all.setTextColor(Color.WHITE);
                tv_all_line.setVisibility(View.VISIBLE);

                Fragment fg = new CheAllFragment();
                fm.beginTransaction().replace(R.id.content_che_frame_layout, fg).commit();

                btn_che_online.setEnabled(true);
                btn_che_online.setTextColor(Color.LTGRAY);
                tv_online_line.setVisibility(View.INVISIBLE);

                btn_che_add.setEnabled(true);
                btn_che_add.setTextColor(Color.LTGRAY);
                tv_add_line.setVisibility(View.INVISIBLE);
            }
        });

        btn_che_online.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                btn_che_online.setEnabled(false);
                btn_che_online.setTextColor(Color.WHITE);
                tv_online_line.setVisibility(View.VISIBLE);

                Fragment fg = new CheOnlineFragment();
                fm.beginTransaction().replace(R.id.content_che_frame_layout, fg).commit();

                btn_che_all.setEnabled(true);
                btn_che_all.setTextColor(Color.LTGRAY);
                tv_all_line.setVisibility(View.INVISIBLE);

                btn_che_add.setEnabled(true);
                btn_che_add.setTextColor(Color.LTGRAY);
                tv_add_line.setVisibility(View.INVISIBLE);
            }
        });

        btn_che_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                btn_che_add.setEnabled(false);
                btn_che_add.setTextColor(Color.WHITE);
                tv_add_line.setVisibility(View.VISIBLE);

                Fragment fg = new CheAddFragment();
                fm.beginTransaction().replace(R.id.content_che_frame_layout, fg).commit();

                btn_che_all.setEnabled(true);
                btn_che_all.setTextColor(Color.LTGRAY);
                tv_all_line.setVisibility(View.INVISIBLE);

                btn_che_online.setEnabled(true);
                btn_che_online.setTextColor(Color.LTGRAY);
                tv_online_line.setVisibility(View.INVISIBLE);
            }
        });

        return view;
    }
}
